package be.kul.osgi.ds.myagent;

import be.kul.osgi.ds.irole.IRole;
import be.kul.osgi.ds.irole.ITask;
import be.kul.osgi.ds.myagent.Role.TaskHandler;

public class Commitment implements Cloneable {

	public ITask task;
	public String xmlTask;
	
	public String StateOfTask;
	
	public static MyAgent agent;
	
	public long start;
	public long end;
	public long due;
	//estimated time to fullfill task 
	public long time;
	
	public long getTime() {
		return time;
	}

	public long getDue() {
		return due;
	}

	public Commitment(ITask task, MyAgent a)
	{
		if (Commitment.agent == null){
			Commitment.agent = a;
		}
		this.task = task;
		this.due = task.getDue();
	}
	
	
	public Commitment(String xmlTask, MyAgent a){
		if (Commitment.agent == null){
			Commitment.agent = a;
		}
		this.xmlTask = xmlTask;
		this.due = Long.parseLong(agent.XMLStreamservice.getValue(xmlTask, "due"));
		this.time = Long.parseLong(agent.XMLStreamservice.getValue(xmlTask, "duration"));
		//time
		//start
		//end
	}
	
	public Commitment(String xmlTask, String xmlState, MyAgent a){
		if (Commitment.agent == null){
			Commitment.agent = a;
		}
		this.xmlTask = xmlTask;
		this.StateOfTask = xmlState;
		this.due = Long.parseLong(agent.XMLStreamservice.getValue(xmlTask, "due"));
		this.time = Long.parseLong(agent.XMLStreamservice.getValue(xmlTask, "duration"));
		//time
		//start
		//end
	}
	
	public void XMLtoTask(){
		TaskHandler th = new TaskHandler(agent);
		IRole r = th.getRoleFromTask(this.xmlTask);
		this.task = r.makeTask(xmlTask);
	}
	
	public void LinkTask(ITask task){
		this.task = task;
	}
	
//	public String getfeatures() throws IOException, URISyntaxException {
//		Properties properties = new Properties();
//		//Bundle bundle = BundleReference.class.cast(r.getClass().getClassLoader()).getBundle();
//		InputStream input = role.getClass().getResourceAsStream("role.properties");
//		properties.load(input);
//		return properties.toString();
//	}
	
//	public long getDue() throws IOException
//	{
//		Properties properties = new Properties();
//		//Bundle bundle = BundleReference.class.cast(r.getClass().getClassLoader()).getBundle();
//		//InputStream input = role.getClass().getResourceAsStream("role.properties");
//		//properties.load(input);
//		//long l = Long.parseLong(properties.getProperty("due"));
//		return l;
//	}
	
//	public long getTime() throws IOException{
//		Properties properties = new Properties();
//		//Bundle bundle = BundleReference.class.cast(r.getClass().getClassLoader()).getBundle();
//		InputStream input = role.getClass().getResourceAsStream("role.properties");
//		properties.load(input);
//		long l = Long.parseLong(properties.getProperty("time"));
//		return l;
//	}


	public static MyAgent getAgent() {
		return agent;
	}


	public static void setAgent(MyAgent agent) {
		Commitment.agent = agent;
	}
	
	
}
